
com.sxnsx.xnaja.ui.overlay = function (){
    var pub = {};
    var priv = {};
    this.downloader = null;

    this.updata_status = function (area, str) {
        var id = 'xnaja_' + area + '_status_label';
        xnaja_app.utilities.$(id).value = str;
    };


    //callback methods
    this.menu_click_cb = function (event) {
        if (event.button) { //Right Click, pop menu
            document.getElementById("xnaja_menu").showPopup(
                document.getElementById("xnaja_icon"),
                -1, -1, "popup", "topright", "bottomright");
        }
    };

    this.download_menuitem_cb = function (method) {
        if (this.downloader != null && this.downloader.working) {
            alert(xnaja_app.utilities.get_local_string('err_downloading_is_processing_alert'));
            return;
        }
        var orig_url = getBrowser().selectedBrowser.webNavigation.currentURI;
        var url = orig_url.prePath + orig_url.path;
        var m = xnaja_app.utilities.match_site(url);
        if (m == null) {
            alert(xnaja_app.utilities.get_local_string('err_url_alert'));
            return ;
        } else {
            this.downloader = new xnaja_common.downloaders[m][1]();
            //alert('Using ('+m+'):' + this.downloader.tag);

            if (!this.downloader.prompt(url, method)) {
                return ;
            }
            this.updata_status('download', 'Starting');
            this.downloader.working = true;
            this.downloader.do(url)
            this.downloader.working = false;
            this.updata_status('download', '');

        }
    };

    this.about_menuitem_cb = function () {
        window.open('http://www.sxnsx.com/xnaja/');
    };

    this.stop_menuitem_cb = function (act) {
        this.downloader.stop();
        this.updata_status('download', '');
        this.updata_status('upload', '');
    };

};
com.sxnsx.cexport(com.sxnsx.xnaja.ui.overlay);

